package com.ruoyi.hr.controller.hr.contractmanage;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.contractmanage.ChangeContractService;
import com.ruoyi.hr.service.contractmanage.NewSignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zeo
 * @explain 合同变更登记
 * @date 2020/3/24
 */
@Controller
@RequestMapping("/contractManage/changeContract")
public class ChangeContractController extends BaseController {

    @Autowired
    ChangeContractService changeContractService;

    @Autowired
    AuthorityService authorityService;

    @Autowired
    NewSignService newSignService;

    private String prefix = "hr/contractmanage/change";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String changeContract() {
        return prefix + "/changeContract";
    }

    @RequestMapping("/findDataList")
    @ResponseBody
    public TableDataInfo findDataList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(changeContractService.findDataList(map, authority));
    }

    @GetMapping("/addEmp")
    public String addEmp() {
        return prefix + "/addEmp";
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Map map = changeContractService.findDataById(id);
        mmap.put("emp", map);
        //公司
        mmap.put("companys", newSignService.findComp());
        return prefix + "/edit";
    }


    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(changeContractService.edit(map));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(changeContractService.remove(ids));
    }
}
